﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FilmManagement2.Founction;
using System.Data;
using System.Data.SqlClient;

namespace FilmManagement2.WebPage
{
    public partial class BookPage_3 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           // Label1.Text = Session["FilmId"].ToString();
           // Label2.Text = Session["Seat"].ToString();
           // Label3.Text = Session["StartTime"].ToString();
            //Label4.Text = Session["StudioNumber"].ToString();
            ConnectToSql cts = new ConnectToSql();
           int filmid = Convert.ToInt32(Session["FilmId"].ToString());
           DataSet ds=cts.GetFilmByID(filmid);
           FilmNamelbl2.Text=ds.Tables[0].Rows[0][1].ToString();
           StartTilmelbl2.Text = Session["StartTime"].ToString();
           StudioNumber2lbl.Text = Session["StudioNumber"].ToString();
           SeatLocation2lbl.Text = Session["Seat"].ToString();
           Pricelbl2.Text = Session["Price"].ToString();
            subcustomeridlbl1.Visible = false;
            subfilmnamelbl1.Visible = false;
            subseatnumberlbl1.Visible = false;
            substudionumberlbl1.Visible = false;
            substarttimelbl1.Visible = false;
            subcustomeridlbl2.Visible = false;
            subfilmnamelbl2.Visible = false;
            subseatnumberlbl2.Visible = false;
            substudionumberlbl2.Visible = false;
            substarttimelbl2.Visible = false;
            submitbut.Visible = false;
            subpricelbl1.Visible = false;
            subpricelbl2.Visible = false;
        }
        protected void admin_Click(object sender, EventArgs e)
        {

            if (submit.Visible == false)
            {
                submit.Visible = true;
                accountlbl.Visible = true;
                txtAccount.Visible = true;
                passwordlbl.Visible = true;
                txtPassword.Visible = true;
            }
            else
            {
                submit.Visible = false;
                accountlbl.Visible = false;
                txtAccount.Visible = false;
                passwordlbl.Visible = false;
                txtPassword.Visible = false;
            }

        }



        protected void bookticketbut_Click(object sender, EventArgs e)
        {
            Response.Redirect(@"BookPage_1.aspx");
        }

        protected void submit_Click(object sender, EventArgs e)
        {
            ConnectToSql cts = new ConnectToSql();
            if (cts.AdminLog(txtAccount.Text, txtPassword.Text))
            {
                Session["AdminName"] = txtAccount.Text;
                Response.Redirect(@"AdminPage.aspx");
            }
            else
            {
                Response.Write("<script>alert('登陆失败')</script>");

            }

        }

        protected void hombut_Click(object sender, EventArgs e)
        {
            Response.Redirect(@"MainPage.aspx");
        }

        protected void bookticketbut_Click1(object sender, EventArgs e)
        {
            Response.Redirect(@"BookPage_1.aspx");
        }

        protected void suggestbut_Click(object sender, EventArgs e)
        {
            Response.Redirect(@"SuggestionPage.aspx");
        }

        protected void previewbut_Click(object sender, EventArgs e)
        {
           
            if (customidentitytxt.Text == "")
            {
                Response.Write("<script>alert('请输入您的密码，以便核对信息')</script>");
            }
            else
            {
                    subcustomeridlbl1.Visible = true;
                    subfilmnamelbl1.Visible = true;
                    subseatnumberlbl1.Visible = true;
                    substudionumberlbl1.Visible = true;
                    substarttimelbl1.Visible = true;
                    subcustomeridlbl2.Visible = true;
                    subfilmnamelbl2.Visible = true;
                    subseatnumberlbl2.Visible = true;
                    substudionumberlbl2.Visible = true;
                    substarttimelbl2.Visible = true;
                    submitbut.Visible = true;
                    subpricelbl1.Visible = true;
                    subpricelbl2.Visible = true;
                    subcustomeridlbl2.Text = customidentitytxt.Text;
                    subfilmnamelbl2.Text = FilmNamelbl2.Text;
                    subseatnumberlbl2.Text = SeatLocation2lbl.Text;
                    substarttimelbl2.Text = StartTilmelbl2.Text;
                    subpricelbl2.Text = Pricelbl2.Text;
            }
        }

        protected void submitbut_Click(object sender, EventArgs e)
        {
            int filmid = Convert.ToInt32(Session["FilmId"].ToString());
            int studioid=0;
            if(Session["StudioNumber"].ToString()=="One")
            {
            studioid=1;
            }
              if(Session["StudioNumber"].ToString()=="Two")
            {
            studioid=2;
            }
                if(Session["StudioNumber"].ToString()=="Three")
            {
            studioid=3;
            }

            ConnectToSql cts = new ConnectToSql();
             bool b=cts.AddTicketList(filmid,studioid,Session["Seat"].ToString(),Convert.ToDateTime(Session["StartTime"].ToString()),customidentitytxt.Text,true,Convert.ToDecimal(Session["Price"].ToString()));
            if (b)
            {
                if (Session["StudioNumber"].ToString() == "One")
                {
                    cts.UpdateMovieStudioOne(filmid, Convert.ToDateTime(Session["StartTime"].ToString()), Session["Seat"].ToString());
                }
                if (Session["StudioNumber"].ToString() == "Two")
                {
                    cts.UpdateMovieStudioTwo(filmid, Convert.ToDateTime(Session["StartTime"].ToString()), Session["Seat"].ToString());
                }
                if (Session["StudioNumber"].ToString() == "Three")
                {
                    cts.UpdateMovieStudioThree(filmid, Convert.ToDateTime(Session["StartTime"].ToString()), Session["Seat"].ToString());
                }
                
                Response.Write("<script>alert('订票成功')</script>");
            }
            else
            Response.Write("<script>alert('订票失败,详情请拨打联系电话OOXX')</script>");

        }
    }
}